<script setup lang="ts">
// 通过defineEmits编译器宏生成emit方法
const emit = defineEmits(["select-user"]);
// 选择用户
const selectUser = (index: number) => {
  emit("select-user", index);
};

// 通过defineProps编译器宏生成props方法
const props = defineProps({
  currentSelectIndex: {
    type: Number,
    default: -1,
  },
});
</script>

<template>
  <div
    class="item"
    v-for="item in 5"
    :key="item"
    @click="selectUser(item)"
    :class="{ active: currentSelectIndex === item }"
  >
    <div class="left">
      <el-avatar
        shape="square"
        :size="50"
        :src="''"
      />
    </div>
    <div class="center">
      <div class="nickname">
        {{ item === 1 ? "心跳检测" : "我的名字六字我的名字六字我的名字六字" }}
      </div>
      <div class="simple-msg">这是我发的消息，也是发个我看的消息</div>
    </div>
    <div class="right">
      <div class="time">18:00</div>
    </div>
  </div>
</template>

<style lang="less" scoped>
.item {
  padding: 8px 10px;
  margin-bottom: 10px;
  height: 50px;
  display: flex;
  cursor: default;
  &:hover {
    background-color: #eaeaea;
  }
  &.active {
    background-color: #e4e4e4;
  }
  .left {
    width: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .center {
    flex: 1;
    min-width: 0; //允许flex项目收缩到小于内容尺寸
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    margin-left: 6px;
    text-align: left;
    font-size: 15px;
    .nickname {
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      color: #161616;
    }
    .simple-msg {
      font-size: 13px;
      color: #aaa;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
  }
  .right {
    width: 30px;
    font-size: 12px;
    color: #aaa;
  }
}
</style>